package com.javasm.aftersales;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.javasm.commons.base.BaseController;
import com.javasm.commons.entity.AxiosResult;
import com.javasm.commons.entity.TableDatas;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping("salesReturnCommodity")
public class SalesReturnCommodityController extends BaseController {
    @Resource
    private SalesReturnCommodityService salesReturnCommodityService;

    @GetMapping("{id}")
    public AxiosResult getByid(@PathVariable String id) {
        SalesReturnCommodity obj = this.salesReturnCommodityService.getById(id);
        return suc(obj);
    }
    
    @GetMapping
    public TableDatas list(SalesReturnCommodity obj) {
        startPage();
        List<SalesReturnCommodity> list = this.salesReturnCommodityService.list(new QueryWrapper(obj));
        return toTableDatas(list);
    }
    

    @PostMapping
    public AxiosResult add(@RequestBody SalesReturnCommodity salesReturnCommodity) {
        boolean b = this.salesReturnCommodityService.save(salesReturnCommodity);
        return isok(b);
    }
    @PutMapping
    public AxiosResult updateById(@RequestBody SalesReturnCommodity salesReturnCommodity) {
        boolean b = this.salesReturnCommodityService.updateById(salesReturnCommodity);
        return isok(b);
    }
    
    @DeleteMapping("{ids}")
    public AxiosResult delByIds(@PathVariable String ids) {
        String[] idsArray = ids.split(",");
        boolean b = this.salesReturnCommodityService.removeByIds(Arrays.asList(idsArray));
        return isok(b);
    }
}

